package com.pickgliss.effect
{
	import flash.display.DisplayObject;
	import flash.utils.Dictionary;

	public final class EffectManager
	{
		
		private static var _instance:EffectManager;
		private var _effects:Dictionary;
		public static function get Instance ():EffectManager
		{
			if(_instance == null)
			{
				_instance = new EffectManager();
			}
			return _instance;
		}
		
		private var _effectIDCounter:int = 0;
		public function getEffectID():int
		{
			return _effectIDCounter++;
		}

		public function EffectManager()
		{
			_effects = new Dictionary();
		}
		
		public function creatEffect(type:int,target:DisplayObject,...args):IEffect
		{
			var effect:IEffect = creatEffectByEffectType(type);
			effect.init(target,args);
			_effects[effect.id] = effect;
			return effect
		}
		/** 取得Effect的Target */
		public function getEffectByTarget($target:DisplayObject):IEffect{
			for each(var effect:IEffect in _effects){
				if($target == effect.target){
					return effect
				}
			}
			return null;
		}
		public function removeEffect(effect:IEffect):void
		{
			effect.dispose();
			delete _effects[effect.id];
		}
		
		public function creatEffectByEffectType(type:int):IEffect
		{
			var effect:IEffect;
			switch(type)
			{
				case EffectTypes.ADD_MOVIE_EFFECT:
					effect = new AddMovieEffect(getEffectID());
					break;
				case EffectTypes.SHINER_ANIMATION:
					effect = new ShinerAnimation(getEffectID());
					break;
				case EffectTypes.ALPHA_SHINER_ANIMATION:
					effect = new AlphaShinerAnimation(getEffectID());
					break;
			}
			return effect;
		}
	}
}